/**
 * userInfo
 *
 * @author LongShu 2017/06/09
 */
(function () {
    var userInfoDiv = new Vue({
        el: "#userInfo",
        data: {
            msg: null,
            username: null,
            userInfoData: {},
            showInfo: false
        },
        methods: {
            getUserInfo: function (username) {
                this.$http.get(fixUrl("user/userInfo/" + username)).then(function (response) {
                    $('.alert').hide();
                    var webData = new WebData(response.body);
                    if (webData.isError()) {
                        this.showMsg(webData.msg);
                        return;
                    }
                    this.userInfoData = webData.data;
                    this.showInfo = true;
                }, function (response) {
                    console.warn(response.body);
                    this.showMsg("获取用户信息失败!");
                });
            },
            showUserInfo: function (username) {
                if (!username) {
                    alert("请登录吧!");
                    toLocation("view/login");
                    return;
                }
                this.getUserInfo(username);
            },
            queryUserInfo: function () {
                if (!this.username) {
                    this.showMsg("请输入用户名!");
                    return;
                }
                this.getUserInfo(this.username);
            },
            showMsg: function (msg) {
                this.msg = msg;
                $('.alert').show();
            }
        }
    });
})();
